package com.lanou3g.code0418.control;

import java.util.concurrent.ForkJoinPool;

/**
 * Created by dllo on 18/4/18.
 */
public class Test03 {
    public static void main(String[] args) {
        long start = System.currentTimeMillis();
        addWithJoin(100000000L);
        long mid = System.currentTimeMillis();
        System.out.println("消耗时间:" + (mid - start) + "ms");

        addWithNormal(100000000L) ;
        long end = System.currentTimeMillis();
        System.out.println("------>" + (end - mid) + "ms");


    }

    public static void addWithNormal(long target) {
        long sum = 0L;
        for (long i = 0; i <= target; i++) {
            sum += i;
        }
    }

    public static void addWithJoin(long target) {
        SumTask task = new SumTask(0L, target);
        //专门用来启动task的
        ForkJoinPool fjp = new ForkJoinPool();
        Long result = fjp.invoke(task);//启动任务,并得到结果
        System.out.println("结果是:" + result);
    }
}
